package com.zlp.netty.component;

import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.NettyRuntime;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author: zhulaiping
 * @time: 2022/8/30 14:12
 */
@Slf4j //多线程时，使用日志打印可以看出哪个线程在执行
public class EventLoopDemo_1 {


    public static void main(String[] args) {
        EventLoopGroup group = new NioEventLoopGroup(2);//处理io事件，普通任务，定时任务
        //DefaultEventLoopGroup group1 = new DefaultEventLoopGroup();//处理普通任务和定时任务
        //System.out.println(NettyRuntime.availableProcessors());
        //获取下一个事件循环对象
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());

        /*group.next().submit(()->{
            log.debug("ok");
        });*/

        group.next().scheduleAtFixedRate(()->{
            log.debug("ok");
        },1,1, TimeUnit.SECONDS);

        log.debug("main ok");
    }
}
